package com.efast.cafe.portal.controller.api;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.efast.cafe.framework.bean.ResultBean;
import com.efast.cafe.framework.controller.AbstractController;
import com.efast.cafe.framework.exception.ServiceException;
import com.efast.cafe.portal.bean.api.PoratalApiServiceSampleValidBean;
import com.efast.cafe.portal.entity.api.PortalApiServiceSample;
import com.efast.cafe.portal.service.api.IPortalApiServiceSampleService;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.support.RequestContext;

import com.alibaba.fastjson.JSONObject;

import org.springframework.beans.factory.annotation.Autowired;

/**
 * <p>
 * Controller
 * </p>
 * <p>
 * Table: portal_api_service_sample - 服务示例
 * </p>
 *
 * @since 2017-08-10 02:39:04
 */
@Controller
@RequestMapping("/frame_center/api")
public class PortalApiServiceSampleController extends AbstractController {

	@Autowired
	private IPortalApiServiceSampleService portalApiServiceSampleService;

	

	

	

	/**
	 * sample请求响应描述验证bean
	 * @param request
	 * @param sampleBean
	 * @return ResultBean
	 * @Author Administrator
	 * @Date 2017年8月31日
	 */
	@RequestMapping("service/sample/valide")
	public @ResponseBody ResultBean valideSampleParam(HttpServletRequest request, PoratalApiServiceSampleValidBean sampleBean) {
//		RequestContext context = new RequestContext(request);
		ResultBean result = new ResultBean();
		String reqDefine=null, resDefine=null,sampleResDefine=null,sampleReqDefine=null;
		if(sampleBean.getReqDefine()!=null){
			 reqDefine=sampleBean.getReqDefine();
		}
		if(sampleBean.getResDefine()!=null){
			 resDefine=sampleBean.getResDefine();
		}
		if(sampleBean.getSampleReqDefine()!=null){
			sampleReqDefine =sampleBean.getSampleReqDefine();
		}
		if(sampleBean.getSampleResDefine()!=null){
			sampleResDefine=sampleBean.getSampleResDefine();
		}
		try{
			result.setSuccess(true);
//			portalApiServiceSampleService.valideSampleParams(reqDefine, sampleReqDefine, resDefine, sampleResDefine);
			result.setMessage(SUCCESS);
		}catch(Exception e){
			if(e instanceof ServiceException){
				result.setMessage(e.getMessage());
			}
			result.setSuccess(false);
			
		}
		
		return result;

	}
	/**
	 * 删除 uri数据示例
	 * @param id
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "service/sample/detail")
	public @ResponseBody ResultBean detailUriSample(@RequestBody PortalApiServiceSample portalApiServiceSample, HttpServletRequest request,
			HttpServletResponse response) {
		RequestContext context = new RequestContext(request);
		ResultBean result = new ResultBean(true,SUCCESS);
		try {
			PortalApiServiceSample sample = portalApiServiceSampleService.detailUriSample(portalApiServiceSample);
			result.setObject(sample);
		} catch (Exception e) {
			result.setSuccess(false);
			if (e instanceof ServiceException) {
				result.setMessage(context.getMessage(e.getMessage()));
			} else {
				result.setMessage(context.getMessage(FAILURE));
			}
		}
		return result;
	}
}